home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / asm / alib11b.zip / CODE1.ZIP / DISPGRAP / CRT_LINE.C < prev    next >
Text File  |  1985-04-05  |  3KB  |  127 lines

  1.  
  2.  
  3.  
  4.  
  5. /******************************************************************
  6.  *
  7.  * name        crt_line - plot lines w/ BIOS point set routine
  8.  *
  9.  * synopsis    crt_line(row1,col1,row2,col2,color);        
  10.  *        int row1,col2,row2,color;
  11.  *
  12.  * description    This routine uses a simple octantal DDA to plot 
  13.  *        lines on your graphics screen.  The screen 
  14.  *        needs to be set to graphics mode, of course...
  15.  *
  16.  * notes    This routine is still written in 'C'.  It is faster 
  17.  *        than many of the other line draw routines I have seen
  18.  *        around, but still relatively slow compared to assembler.
  19.  *
  20.  *        Since this routine uses the BIOS point set routine,
  21.  *        it will run on color or mono display adaptors, in
  22.  *        any supported graphics mode.  The disadvantage of 
  23.  *        using the BIOS point set routine is that it is
  24.  *        extremely slow.....  The speed of this routine is
  25.  *        entirely limited by the speed of the BIOS pset call. 
  26.  * 
  27.  * bugs        Better be sure that your x and y values are in range
  28.  *        no range checking is done.
  29.  ********************************************************************/
  30.  
  31. crt_line(startx, starty, endx, endy, color)
  32. int  startx, starty, endx, endy, color;
  33.     {
  34.     int count, deltax, deltay, error, t;
  35.  
  36.  
  37.     if (endx < startx)
  38.         {
  39.         t = startx;             /* fold quadrants 2, 3 to 1, 4  */
  40.         startx = endx;
  41.         endx = t;
  42.         t = starty;
  43.         starty = endy;
  44.         endy = t;
  45.         }
  46.     deltax = endx - startx;
  47.     deltay = endy - starty;
  48.     if (deltay < 0)
  49.         {
  50.         if (-deltay > deltax)   /* octant 7             */
  51.             {
  52.             count = -deltay;
  53.             error = deltay / 2;
  54.             do
  55.                 {
  56.         crt_pset(startx, starty, color);
  57.  
  58.                 starty--;
  59.                 if ((error += deltax) >= 0)
  60.                     {
  61.                     startx++;
  62.                     error += deltay;
  63.                     }
  64.                 }
  65.             while (--count >= 0);
  66.             }
  67.         else                    /* octant 8             */
  68.             {
  69.             count = deltax;
  70.             error = -deltax / 2;
  71.             do
  72.                 {
  73.  
  74.         crt_pset(startx, starty, color);
  75.  
  76.                 startx++;
  77.                 if ((error -= deltay) >= 0)
  78.                     {
  79.                     starty--;
  80.                     error -= deltax;
  81.                     }
  82.                 }
  83.             while (--count >= 0);
  84.             }
  85.         }
  86.     else if (deltay > deltax)       /* octant 2         */
  87.         {
  88.         count = deltay;
  89.         error = -deltay / 2;
  90.         do
  91.             {
  92.         crt_pset(startx , starty, color);
  93.  
  94.             starty++;
  95.             if ((error += deltax) >= 0)
  96.                 {
  97.                 startx++;
  98.                 error -= deltay;
  99.                 }
  100.             }
  101.         while (--count >= 0);
  102.         }
  103.     else                        /* octant 1             */
  104.         {
  105.         count = deltax;
  106.         error = -deltax/2;
  107.         do
  108.             {
  109.   
  110.         crt_pset(startx , starty, color);
  111.  
  112.             startx++;
  113.             if ((error += deltay) >= 0)
  114.                 {
  115.                 starty++;
  116.                 error -= deltax;
  117.                 }
  118.             }
  119.         while (--count >= 0);
  120.         }
  121.     }
  122.  
  123.  
  124.  
  125.  
  126.  
  127.